<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加车辆</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all" />
    <script type="text/javascript"  th:src="@{/lib/layui/layui.js}"></script></head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form" lay-filter="sectionForm">
        <input type="hidden" id="dataRow" name="strId" th:value="${StrId}">
        <input type="hidden"  name="id" th:value="${id}">
        <div class="layui-form-item">
            <label class="layui-form-label">区间名称</label>
            <div class="layui-inline">
                <div class="layui-input-block">
                    <input type="text" name="rangeName"
                           th:value="${DSendingMaintenanceList!=null?DSendingMaintenanceList.rangeName:''}"
                           placeholder="请输入区间名称" autocomplete="off" class="layui-input"
                           lay-verify="required">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">区间类型</label>
            <div class="layui-inline">
                <select id="selectList" lay-verify="required" name="sectionType"
                        lay-search="" style="width:100px;">
                    <option value="1" th:selected="${DSendingMaintenanceList!=null?(DSendingMaintenanceList.sectionType == 1?true:''):''}">目的区间
                    </option>
                    <option value="0" th:selected="${DSendingMaintenanceList!=null?(DSendingMaintenanceList.sectionType == 0?true:''):''}">寄件区间
                    </option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">寄件区域/目的区域：</label><a class="layui-btn" id="choose">点击选择</a>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                        <textarea name="str" th:text="${Str!=null?Str:''}"
                                  placeholder="" class="layui-textarea" readonly>
                        </textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">备注:</label>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                    <textarea name="remark" value=""
                              th:text="${DSendingMaintenanceList!=null?DSendingMaintenanceList.remark:''}"
                              placeholder="" class="layui-textarea">
                    </textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">确认保存</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script>
    layui.use(["element", "form", "jquery"], function () {
        var form = layui.form;
        $ = layui.jquery;
        var layer = parent.layer
        form.render('select');


        var idx = parent.layer.getFrameIndex(window.name);
        //判断下拉框选中的类型，进行相应的选择
        $('#choose').click(function () {
            var strId = $("#dataRow").val();

            console.log("strId :"+strId)
            if (strId != undefined && strId != '' && strId != null) {
                strId = "?strId=" + strId.substring(1,strId.length);
            } else {
                strId = '';
            }
            var id = $("select option:checked").val();
            var op = "";
            if (id == 1) {
                op = "目的";
            } else if (id == 0) {
                op = "寄件";
            }

            //获取当前的index
             parent.layui.layer.open({
                title: "选择" + op + "区",
                type: 2,
                area: ['780px', '690px'],
                content: "/page/sectionTree/"+idx+"/" + id +strId

            })

        })

            form.on("submit(add)", function (data) {
                var flag = $("[name='id']").val();
                var method = "";
                if (flag == null || flag == '' || flag == undefined) {
                    method = "add"
                } else {
                    method = "edit";
                }
                console.log("flag:"+flag)
                console.log("method:"+method)
                $.post("/api/section/"+method,data.field,function(d){
                    if (d.code == 200) {
                        top.layer.close(idx);
                        top.layer.msg("区间添加成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    } else {
                        layer.msg(d.msg,{"icon":2});
                    }
                });

                return false;
            });

    });


</script>
</body>
</html>
